package com.chezai.client.fragment;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.chezai.client.R;
import com.chezai.client.adapter.CoachTrainRecordAdapter;
import com.chezai.client.bean.ClassRecord;
import com.chezai.client.bean.StudentStudyRecord;
import com.chezai.client.dao.manager.StudentStudyRecordDaoManager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;


/**
 * 教练培训记录
 * Created by likunyang on 2017/9/13.
 */

public class CoachTrainRecordFragment extends BaseFragment {
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    @BindView(R.id.iv_empty)
    ImageView ivEmpty;
    private CoachTrainRecordAdapter mAdapter;
    private long coachLoginRecordId;

    public static CoachTrainRecordFragment newInstance(long coachLoginRecordId) {
        Bundle args = new Bundle();
        args.putLong("coachLoginRecordId", coachLoginRecordId);
        CoachTrainRecordFragment fragment = new CoachTrainRecordFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_coach_train_record;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        LinearLayoutManager manager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(manager);
        mAdapter = new CoachTrainRecordAdapter(R.layout.item_coach_train_record);
        recyclerView.setAdapter(mAdapter);
    }

    @Override
    public void initData() {
        coachLoginRecordId = getArguments().getLong("coachLoginRecordId");
        List<StudentStudyRecord> studentLoginRecordes = StudentStudyRecordDaoManager.getInstance().findStudentLoginRecordes(coachLoginRecordId);
        List<ClassRecord> classRecords = new ArrayList<>();
        for (StudentStudyRecord studyRecord : studentLoginRecordes) {
            classRecords.add(studyRecord.getClassRecord());
        }
        if (classRecords.size() == 0) {
            ivEmpty.setVisibility(View.VISIBLE);
            recyclerView.setVisibility(View.GONE);
        } else {
            ivEmpty.setVisibility(View.GONE);
            recyclerView.setVisibility(View.VISIBLE);
            mAdapter.setNewData(classRecords);
        }
    }
}
